import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

public class MyController {
    private htmlReader reader;
    private Visualisation myVis;
    private String filename;
    private OpenListener openListener;
//    private SaveListener saveListener;
    private UploadListener uploadListener;
//    private String parentHtmlDirectory;
    public OpenListener getOpenListener() {
        return openListener;
    }

    public ActionListener getUploadListener() {
        return uploadListener;
    }

//

    //
    class OpenListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(".");
            chooser.showOpenDialog(null);
            File f = chooser.getSelectedFile();
            if(f!=null){
            filename = f.getAbsolutePath();
            reader = new htmlReader();

            reader.read(filename);
            reader.copyImages();
            myVis.showFiles(reader.getOutputFileName());
            myVis.getUploadButton().setEnabled(true);
            myVis.update();
            }

        }
    }


    public MyController(Visualisation myVis) {
        this.myVis = myVis;
        openListener = new OpenListener();
        uploadListener = new UploadListener();
        myVis.setController(this);
    }

    class UploadListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
           myVis.setUploadDialog( new UploadDialog(myVis.getFrame(), reader.getOutputFile()));

        }
    }
}
